#include "breathing.h"
#include <QDebug>

Breathing::Breathing(QObject *parent) :
    QObject(parent)
{
}

void Breathing::addPoint(double x, double y)
{
    t << x;
    s << y;
}

QVector<double> *Breathing::getX()
{
    return &t;
}

QVector<double> *Breathing::getY()
{
    return &s;
}

QVector<double> *Breathing::derivative()
{
    for (int i = 0; i < xrange; i++)
    {
        der << 0.0;
    }

    double dx = t.at(xrange * 2) - t.at(0);
    for (int i = xrange; i < (s.size() - xrange); i++)
    {
        double dy = s.at(i + xrange) - s.at(i - xrange);
        der << dy / dx;
    }

    for (int i = s.size() - xrange; i < s.size(); i++)
    {
        der << 0.0;
    }

    return &der;
}

QVector<double> *Breathing::getDerivative()
{
    return &der;
}

QVector<double> *Breathing::type()
{
    this->derivative();
    for (int i = 0; i < (der.size()); i++)
    {
        if (der[i] < -threshold)
        {
            breathingType << -1.0;
        }
        else if (der[i] > threshold)
        {
            breathingType << 1.0;
        }
        else
        {
            breathingType << 0.0;
        }
    }
    return &breathingType;
}
